﻿namespace ExamV5.WorkExam
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmLastAddExamUser : Page
    {
        protected Button butClose;
        protected Button butEnter;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected int intID = 0;
        protected Label labExamName;
        protected Label labJoinExamUser;
        protected Label labPaperUseTime;
        private PublicFun publicFun_0 = new PublicFun();
        protected string strBrowUserCode = "";
        protected string strBrowUserName = "";

        protected void butEnter_Click(object sender, EventArgs e)
        {
            string str = "";
            this.strBrowUserName = base.Request.Form["txtBrowUserName"].ToString().Trim();
            this.strBrowUserCode = base.Request.Form["txtBrowUserCode"].ToString().Trim();
            string[] strArray = this.strBrowUserCode.Split(new char[] { ',' });
            string str2 = "";
            this.butEnter.Enabled = false;
            string connectionString = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
            SqlConnection connection = new SqlConnection(connectionString);
            connection.Open();
            SqlCommand command = new SqlCommand {
                Connection = connection
            };
            string str4 = "";
            string str5 = "";
            SqlConnection connection2 = new SqlConnection(connectionString);
            connection2.Open();
            SqlCommand command2 = new SqlCommand("select a.ExamName,a.RubricDist,a.SubjectID,a.SubjectName from WorkPaperInfo a where  a.ID=" + this.intID, connection2);
            SqlDataReader reader = command2.ExecuteReader(CommandBehavior.CloseConnection);
            if (reader.Read())
            {
                reader["RubricDist"].ToString();
                reader["SubjectID"].ToString();
                str4 = reader["SubjectName"].ToString();
                str5 = reader["ExamName"].ToString();
            }
            reader.Close();
            command2.Dispose();
            connection2.Close();
            connection2.Dispose();
            try
            {
                for (int i = 0; i < strArray.Length; i++)
                {
                    if (strArray[i].Trim() != "")
                    {
                        str = "ID#ID";
                        str2 = "Insert into WorkPaperData(PaperID,UserCode,RubricS,RubricD,SortInfo) ";
                        str2 = string.Concat(new object[] { str2, " select PaperID,'", strArray[i].Trim(), "' as UserCode,RubricS,RubricD,'", str, "' as SortInfo from WorkPaperData where UserCode='' and PaperID=", this.intID });
                        command.CommandText = str2;
                        command.ExecuteNonQuery();
                        str2 = string.Concat(new object[] { "Insert into WorkExamUser(UserCode,PaperID,ExamName,SubjectName,GetCountFen,Flag,LoginIP,LastDate) values('", strArray[i].Trim(), "',", this.intID, ",'", str5, "','", str4, "','0','A','','')" });
                        command.CommandText = str2;
                        command.ExecuteNonQuery();
                    }
                }
                this.publicFun_0.ExecuteSql("insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('补录考试人员-职业测评组卷且试卷生成成功！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')");
                base.Response.Write("<script>alert('补录考试人员-职业测评组卷且试卷生成成功！');window.close();</script>");
            }
            catch
            {
                base.Response.Write(@"<script>alert('确定考试人员时出错！\n\n补录人员名单中可能已经纳入考试人员范围，请核实！')</script>");
            }
            finally
            {
                connection.Close();
                connection.Dispose();
            }
        }

        private void method_0()
        {
            try
            {
                SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                connection.Open();
                SqlCommand command = new SqlCommand("select * from WorkPaperInfo where ID=" + this.intID, connection);
                SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                if (reader.Read())
                {
                    this.labExamName.Text = reader["ExamName"].ToString();
                    this.labPaperUseTime.Text = reader["PaperStartTime"].ToString() + "——" + reader["PaperEndTime"].ToString();
                }
                reader.Close();
                command.Dispose();
                connection.Close();
                connection.Dispose();
                this.labJoinExamUser.Text = this.publicFun_0.GetValues("select '['+UserCode+']'+UserName as UserName from UserInfo where UserCode in(select UserCode from WorkExamUser where PaperID=" + this.intID + ")");
            }
            catch
            {
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            this.intID = Convert.ToInt32(base.Request["ID"].ToString());
            if ((this.httpCookie_0 != null) && (this.httpCookie_0.Value != ""))
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (base.IsPostBack)
                {
                    this.strBrowUserName = base.Request.Form["txtBrowUserName"].ToString().Trim();
                    this.strBrowUserCode = base.Request.Form["txtBrowUserCode"].ToString().Trim();
                }
                else
                {
                    this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString;
                    if (this.publicFun_0.ReturnPaperData() == "Yes")
                    {
                        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                        connection.Open();
                        SqlCommand command = new SqlCommand("select AddPaper,ManagPaper from UserPower where UserCode='" + this.httpCookie_0.Value + "'", connection);
                        SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                        if (reader.Read())
                        {
                            this.ViewState["AddPower"] = reader["AddPaper"].ToString();
                            this.ViewState["ManagPower"] = reader["ManagPaper"].ToString();
                        }
                        reader.Close();
                        command.Dispose();
                        connection.Close();
                        connection.Dispose();
                        if (this.ViewState["ManagPower"].ToString() == "Y")
                        {
                            this.butEnter.Visible = true;
                        }
                        else if (!(this.ViewState["AddPower"].ToString() == "Y"))
                        {
                            this.butEnter.Visible = false;
                        }
                        else if (this.publicFun_0.GetValues("select InputUserCode from PaperInfo where ID=" + this.intID, "InputUserCode") == this.httpCookie_0.Value)
                        {
                            this.butEnter.Visible = true;
                        }
                        else
                        {
                            this.butEnter.Visible = false;
                        }
                        this.butEnter.Attributes.Add("onclick", @"javascript:{if(confirm('确认补录参考人员无误？\n生成试卷需要一定的时间，请耐心等待生成结果！\n\n请勿离开此页面！！！')==false) return false;}");
                        if ((this.intID != 0) && (this.httpCookie_2.Value != "A"))
                        {
                            this.method_0();
                        }
                    }
                    else
                    {
                        base.Response.Write("<script>alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')</script>");
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

